﻿using System;
using System.IO;
using System.Xml.Serialization;

namespace DCS.CalculationClient.Settings
{
    [Serializable]
    public class DcsSettings
    {
        public Guid Id { get; set; }

        public void Save(string path)
        {
            var serializer = new XmlSerializer(typeof(DcsSettings));

            using (var ms = new FileStream(path, FileMode.OpenOrCreate))
            {
                serializer.Serialize(ms, this);
            }
        }

        public static DcsSettings Load(string path)
        {
            if (!File.Exists(path))
                return null;

            var serializer = new XmlSerializer(typeof (DcsSettings));
            try
            {
                using (var ms = new FileStream(path, FileMode.Open))
                {
                    return (DcsSettings)serializer.Deserialize(ms);
                }
            }
            catch 
            {
                return null;
            }
            
        }
    }
}
